//
//  QuizSubmitTopView.m
//  SubmitVCDemo
//
//  Created by Tianlong on 2018/1/24.
//  Copyright © 2018年 Tianlong. All rights reserved.
//

#import "QuizSubmitTopView.h"

#define TopM 37

@interface QuizSubmitTopView ()
@property (weak, nonatomic) IBOutlet UIButton *icon;
@property (weak, nonatomic) IBOutlet UILabel *titleL;
@property (weak, nonatomic) IBOutlet UILabel *subTitleL;
@property (assign, nonatomic) QuizSubmitType vcType;
@property (assign, nonatomic) CGFloat viewH;
@end

@implementation QuizSubmitTopView

- (void)awakeFromNib{
    [super awakeFromNib];
    self.icon.userInteractionEnabled = NO;
}

+ (instancetype)viewType:(QuizSubmitType)type{
    QuizSubmitTopView *head = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([QuizSubmitTopView class]) owner:self options:nil] lastObject];
    head.vcType = type;
    return head;
}

#pragma mark - 根据type进行相关设置

- (void)setVcType:(QuizSubmitType)vcType{
    _vcType = vcType;
    switch (vcType) {
        case QuizSubmitTypeReject://直接驳回,重新答题
            [self.icon setImage:[UIImage imageNamed:@"homeworkpapertest_task_Monkey_icon_normal"] forState:UIControlStateNormal];
            self.titleL.text = @"答案需要重新上传";
            self.subTitleL.text = [NSString stringWithFormat:@"%@\n%@",@"您的答案上传的有问题，已被老师驳回",@"快去重新答题吧~"];
            break;
        case QuizSubmitTypeCorrectReject://订正驳回
            [self.icon setImage:[UIImage imageNamed:@"homeworkpapertest_task_Monkey_icon_normal"] forState:UIControlStateNormal];
            self.titleL.text = @"答案需要重新上传";
            self.subTitleL.text = [NSString stringWithFormat:@"%@\n%@",@"您的答案上传的有问题，已被老师驳回",@"快去重新答题吧~"];
            break;
        case QuizSubmitTypeSubmitSuccess://提交成功
            [self.icon setImage:[UIImage imageNamed:@"homeworkpapertest_task_submitsuccess_icon_normal"] forState:UIControlStateNormal];
            self.titleL.text = @"随堂测提交成功";
            self.subTitleL.text = [NSString stringWithFormat:@"%@\n%@",@"辅导老师正在加班为您批改主观题",@"请耐心等待呦~"];
            break;
            
        default:
            break;
    }
    
    if(vcType == QuizSubmitTypeSubmitSuccess ||
       vcType == QuizSubmitTypeCorrectReject ||
       vcType == QuizSubmitTypeReject){
        
        self.titleL.font = [UIFont fontPingFangSCWithSize:22];
        self.titleL.textColor = [UIColor colorWithHexValue:0x333333];
        
        self.subTitleL.font = [UIFont fontPingFangSCWithSize:14];
        self.subTitleL.textColor = [UIColor colorWithHexValue:0x666666];
    }
    
    // 计算控件的真实高度
    [self layoutIfNeeded];
    CGFloat maxY = MAX(CGRectGetMaxY(self.titleL.frame), CGRectGetMaxY(self.subTitleL.frame));
    self.viewH = MAX(CGRectGetMaxY(self.icon.frame), maxY);
}

#pragma mark - 获取真实高度
- (CGFloat)getRealHeight{
    return self.viewH;
}

+ (CGFloat)getRealHeightWithSubmitType:(QuizSubmitType)type{
    QuizSubmitTopView *view = [QuizSubmitTopView viewType:type];
    return [view getRealHeight];
}
+ (CGFloat)topMargin{
    return TopM;
}
@end
